<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>simSerialRead</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../../index.html" TARGET="_top"><img src="../images/homeImg.png"></a></p>

<h1>Regular API function</h1>
<h3 class=subsectionBar><a name="simSerialRead" id="simSerialRead"></a>simSerialRead / sim.serialRead </h3>
<table class=apiTable>
<tr class=apiTableTr> 
<td class=apiTableLeftDescr>
Description 
</td> 
<td class=apiTableRightDescr>Reads from a previously opened serial port (RS-232). The C version of the function cannot be blocking. See also <a href="simSerialCheck.htm">sim.serialCheck</a> and <a href="simSerialSend.htm">sim.serialSend</a>.<br></td>
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCSyn>
C synopsis
</td> 
<td class=apiTableRightCSyn>simInt simSerialRead(simInt portHandle,simChar* buffer,simInt dataLengthToRead)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCParam>C parameters</td> 
<td class=apiTableRightCParam>
<div><strong>portHandle</strong>: the handle returned by the <a href="simSerialOpen.htm">simSerialOpen</a> function</div>
<div><strong>buffer</strong>: a buffer that will be filled with read data<br>
</div>
<div><strong>dataLengthToRead</strong>: the maximum data length that should be read<br>
</div>
<div></div></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCRet>
C return value
</td> 
<td class=apiTableRightCRet>
<div>-1 if operation was not successful, otherwise the effective data length that was read<br>
</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLSyn>
Lua synopsis
</td> 
<td class=apiTableRightLSyn>string data=sim.serialRead(int portHandle,int dataLengthToRead,boolean blockingOperation,string closingString='',float timeout=0)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLParam>Lua parameters</td> 
<td class=apiTableRightLParam>
<div><strong>portHandle</strong>: the handle returned by the <a href="simSerialOpen.htm">sim.serialOpen</a> function</div>
<div><strong>dataLengthToRead</strong>: the maximum data length that should be read</div>
<div><strong>blockingOperation</strong>: if true and the calling script is running in a thread, then the function only returns when the desired data length was read (or if the closingString was met, or if there was a timeout (see next arguments)<br>
</div>
<div><strong>closingString</strong>: a string (containing any byte value) can be specified, that will break from the blocking operation if a match was found in the incoming data. Useful when you know that a data packet is always ended with a given signature. Can be an empty string for default operation.<br>
</div>
<div><strong>timeout</strong>: duration after which the blocking operation will be aborted, or 0 if the timeout is infinite.</div>
<div></div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLRet>
Lua return values
</td> 
<td class=apiTableRightLRet>
<div><strong>data</strong>: a string containing read data (excluding the closingString if it was specified and found)</div>
</td> 
</tr> 
</table> 


<br>
</td>
</tr>
</table>
</div>
</body>
</html>
